
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:permission_handler/permission_handler.dart';


class PlatformUtils {
  static Future<PackageInfo> getAppPackageInfo() {
    return PackageInfo.fromPlatform();
  }

  static Future<String> getAppVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    return packageInfo.version;
  }

  static Future<String> getBuildNum() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    return packageInfo.buildNumber;
  }

  static Future getDeviceInfo() async {
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    if (Platform.isAndroid) {
      return await deviceInfo.androidInfo;
    } else if (Platform.isIOS) {
      return await deviceInfo.iosInfo;
    } else {
      return null;
    }
  }

  ///申请存储权限
  static Future permissionStorage() async {
    if (defaultTargetPlatform == TargetPlatform.android) {
      PermissionStatus status = await Permission.storage.request();
      return status == PermissionStatus.granted;
    } else {
      PermissionStatus status = await Permission.photos.request();
      return status == PermissionStatus.granted;
    }
  }

  ///申请麦克风权限
  static Future permissionMicrophone() async {
    //Android 麦克风
    if (defaultTargetPlatform == TargetPlatform.android) {
      PermissionStatus status = await Permission.microphone.request();
      return status == PermissionStatus.granted;
    }
  }
}
